package com.example.mingyue.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mingyue.Exception.DataSizeBigException;
import com.example.mingyue.common.PageBean;
import com.example.mingyue.common.Result;
import com.example.mingyue.constant.MessageConstant;
import com.example.mingyue.model.dto.PictureDto;
import com.example.mingyue.model.entity.Picture;
import com.example.mingyue.service.PictureService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 获取图片列表数据
 */
@RestController
@RequestMapping("/picture")
@Slf4j
public class PictureController {

    @Resource
    private PictureService pictureService;

    /**
     * 最终放入搜索接口
     * @param pictureDto
     * @return
     */
    @GetMapping("/list/vo")
    public Result getPictureList(@RequestBody PictureDto pictureDto){

        Integer page = pictureDto.getPage();
        Integer pageSize = pictureDto.getPageSize();

        //限制搜索数据量过大
        if(page > 20){
            throw new DataSizeBigException(MessageConstant.DATA_SIZE_BIG_ERROR);
        }

        String searchText = pictureDto.getSearText();
        IPage<Picture> pageBean = pictureService.searchPicture(searchText,page,pageSize);

        return Result.success(pageBean);
    }



}
